package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         69,
		Discription: "平方根",
		Level:       1,
		Labels: map[string]int{
			"二分查找": 1,
		},
	})
}

func MySqrt(x int) int {
	left := 0
	right := x
	for left <= right {
		mid := left + (right-left)/2
		temp := mid * mid
		if temp == x {
			return mid
		}

		if temp > x {
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	//向下取整
	if left*left > x {
		return left - 1
	} else {
		return left
	}
}
